/*
 * Copyright (c) 2016, Freescale Semiconductor, Inc.
 * Copyright 2016-2020,2022-2023 NXP
 * All rights reserved.
 *
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include "lwip/opt.h"

#if LWIP_TCP
#include <stdio.h>
#include "lwip/apps/httpd.h"
#include "lwip/tcp.h"

#include "lwip/timeouts.h"
#include "lwip/init.h"
#include "netif/ethernet.h"
#include "ethernetif.h"

#include "pin_mux.h"
#include "board.h"
#ifndef configMAC_ADDR
#include "fsl_silicon_id.h"
#endif
#include "fsl_phy.h"
#include "fsl_gpio.h"
#include "fsl_enet.h"
#include "fsl_phylan8741.h"

#include "fsl_p3t1755.h"
#include "fsl_i3c.h"
#include "fsl_port.h"
/*******************************************************************************
 * Definitions
 ******************************************************************************/

/* @TEST_ANCHOR */

/* IP address configuration. */
#ifndef configIP_ADDR0
#define configIP_ADDR0 192
#endif
#ifndef configIP_ADDR1
#define configIP_ADDR1 168
#endif
#ifndef configIP_ADDR2
#define configIP_ADDR2 0
#endif
#ifndef configIP_ADDR3
#define configIP_ADDR3 102
#endif

/* Netmask configuration. */
#ifndef configNET_MASK0
#define configNET_MASK0 255
#endif
#ifndef configNET_MASK1
#define configNET_MASK1 255
#endif
#ifndef configNET_MASK2
#define configNET_MASK2 255
#endif
#ifndef configNET_MASK3
#define configNET_MASK3 0
#endif

/* Gateway address configuration. */
#ifndef configGW_ADDR0
#define configGW_ADDR0 192
#endif
#ifndef configGW_ADDR1
#define configGW_ADDR1 168
#endif
#ifndef configGW_ADDR2
#define configGW_ADDR2 0
#endif
#ifndef configGW_ADDR3
#define configGW_ADDR3 1
#endif


#define TCP_REMOTE_PORT    22222 /* 远端端口 */
#define TCP_LOCAL_PORT     11111  /* 本地端口 */

#define SENSOR_ADDR 0x08U
#define SENSOR_SLAVE_ADDR          0x48U
#define CCC_SETDASA 0x87
#define CCC_RSTDAA  0x06U


/* Ethernet configuration. */
extern phy_lan8741_resource_t g_phy_resource;
#define EXAMPLE_ENET_BASE    ENET0
#define EXAMPLE_PHY_ADDRESS  BOARD_ENET0_PHY_ADDRESS
#define EXAMPLE_PHY_OPS      &phylan8741_ops
#define EXAMPLE_PHY_RESOURCE &g_phy_resource

#define EXAMPLE_CLOCK_FREQ   (50000000U)
#define I3C_MASTER_CLOCK_FREQUENCY CLOCK_GetI3cClkFreq(1)
#define EXAMPLE_MASTER             I3C1
#define EXAMPLE_I3C_OD_BAUDRATE 1500000
#define EXAMPLE_I3C_PP_BAUDRATE 4000000
#define EXAMPLE_I2C_BAUDRATE 400000
#define I3C_TIME_OUT_INDEX 100000000U

#ifndef EXAMPLE_NETIF_INIT_FN
/*! @brief Network interface initialization function. */
#define EXAMPLE_NETIF_INIT_FN ethernetif0_init
#endif /* EXAMPLE_NETIF_INIT_FN */

/*******************************************************************************
 * Prototypes
 ******************************************************************************/

/*******************************************************************************
 * Variables
 ******************************************************************************/
phy_lan8741_resource_t g_phy_resource;

phy_handle_t phyHandle;
struct tcp_pcb *tpcb;
i3c_master_handle_t g_i3c_m_handle;
p3t1755_handle_t p3t1755Handle;
volatile status_t g_completionStatus;
volatile bool g_masterCompletionFlag;



//info for tcp
double temperature = 0;
uint32_t LightFlagt = 0;
volatile bool g_ButtonPress = false;
char * btm = "sw3";
/*******************************************************************************
 * Code
 ******************************************************************************/
static void MDIO_Init(void)
{
    (void)CLOCK_EnableClock(s_enetClock[ENET_GetInstance(EXAMPLE_ENET_BASE)]);
    ENET_SetSMI(EXAMPLE_ENET_BASE, CLOCK_GetCoreSysClkFreq());
}

static status_t MDIO_Write(uint8_t phyAddr, uint8_t regAddr, uint16_t data)
{
    return ENET_MDIOWrite(EXAMPLE_ENET_BASE, phyAddr, regAddr, data);
}

static status_t MDIO_Read(uint8_t phyAddr, uint8_t regAddr, uint16_t *pData)
{
    return ENET_MDIORead(EXAMPLE_ENET_BASE, phyAddr, regAddr, pData);
}


#if LWIP_IPV6
static void print_ipv6_addresses(struct netif *netif)
{
    for (int i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++)
    {
        const char *str_ip = "-";
        if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)))
        {
            str_ip = ip6addr_ntoa(netif_ip6_addr(netif, i));
        }
        PRINTF(" IPv6 Address%d    : %s\r\n", i, str_ip);
    }
}

static void netif_ipv6_callback(struct netif *cb_netif)
{
    PRINTF("IPv6 address update, valid addresses:\r\n");
    print_ipv6_addresses(cb_netif);
    PRINTF("\r\n");
}
#endif /* LWIP_IPV6 */

/*!
 * @brief Interrupt service for SysTick timer.
 */
void SysTick_Handler(void)
{
    time_isr();
}

static err_t tcp_client_recv(void *arg, struct tcp_pcb *tpcb,
                             struct pbuf *p, err_t err)
{
    uint32_t i;
    char cmd = 0;
    /* 数据回传 */
    //tcp_write(tpcb, p->payload, p->len, 1);
    
    if (p != NULL)
    {
        struct pbuf *ptmp = p;
        
        /* 打印接收到的数据 */
        PRINTF("get msg from %d:%d:%d:%d port:%d:\r\n",
            *((uint8_t *)&tpcb->remote_ip.addr),
            *((uint8_t *)&tpcb->remote_ip.addr + 1),
            *((uint8_t *)&tpcb->remote_ip.addr + 2),
            *((uint8_t *)&tpcb->remote_ip.addr + 3),
            tpcb->remote_port);
        
        while(ptmp != NULL)
        {
			cmd = *((char *)p->payload + 0);
            for (i = 0; i < p->len; i++)
            {
                PRINTF("%c", *((char *)p->payload + i));
            }
            
            ptmp = p->next;
        }
		GPIO_PinWrite(BOARD_LED_RED_GPIO,BOARD_LED_RED_GPIO_PIN,1);
		GPIO_PinWrite(BOARD_LED_BLUE_GPIO,BOARD_LED_BLUE_GPIO_PIN,1);
		GPIO_PinWrite(BOARD_LED_GREEN_GPIO ,BOARD_LED_GREEN_GPIO_PIN,1);
        if(cmd == '1'){
			GPIO_PinWrite(BOARD_LED_RED_GPIO,BOARD_LED_RED_GPIO_PIN,0);
		}else if(cmd == '2') {
			GPIO_PinWrite(BOARD_LED_BLUE_GPIO,BOARD_LED_BLUE_GPIO_PIN,0);
		}else if(cmd == '3') {
			GPIO_PinWrite(BOARD_LED_GREEN_GPIO ,BOARD_LED_GREEN_GPIO_PIN,0);
		}
        PRINTF("cmd [%c]\r\n",cmd);
        
        tcp_recved(tpcb, p->tot_len);
        
        /* 释放缓冲区数据 */
        pbuf_free(p);
    }
    else if (err == ERR_OK)
    {
        PRINTF("tcp client closed\r\n");
        
        tcp_recved(tpcb, p->tot_len);
        
        return tcp_close(tpcb);
    }
 
    return ERR_OK;
}


void tcp_client_init(void);

static err_t tcp_client_connected(void *arg, struct tcp_pcb *tpcb, err_t err)
{
    PRINTF("tcp client connected  \r\n");
    
    tcp_write(tpcb, "hello lwip zsy!!", strlen("hello lwip zsy!!"), 0);
 
    /* 注册接收回调函数 */
    tcp_recv(tpcb, tcp_client_recv);
 
    return ERR_OK;
}

 static void client_err(void *arg, err_t err)
 {
     PRINTF("connect error! err[%d]!\n\r",err);
     PRINTF("try to connect to server again!%s!\n\r",lwip_strerr(err));

     //连接失败的时候释放TCP控制块的内存
     tcp_close(tpcb);

     //重新连接
     tcp_client_init();
 }

ip4_addr_t  serverIp;
void tcp_client_init(void)
{
    /* 服务器IP */
    IP4_ADDR(&serverIp, 192, 168, 0, 100);

    /* 创建tcp控制块 */
    tpcb = tcp_new();
    
    if (tpcb != NULL)
    {
        err_t err;
    /* 连接服务器 */
		PRINTF("tcp client to connect svr  \r\n");
        err = tcp_connect(tpcb, &serverIp, TCP_REMOTE_PORT, tcp_client_connected);
		PRINTF("\r\n--srver to conn [ 192, 168, 0, 100 : %d]--%d-\r\n",TCP_REMOTE_PORT,err);
		tcp_err(tpcb, client_err);
    }
}

void delay(void)
{
    volatile uint32_t i = 0;
    for (i = 0; i < 800000; ++i)
    {
        __asm("NOP"); /* delay */
    }
}

status_t I3C_WriteSensor(uint8_t deviceAddress, uint32_t regAddress, uint8_t *regData, size_t dataSize)
{
    status_t result                  = kStatus_Success;
    i3c_master_transfer_t masterXfer = {0};
    uint32_t timeout                 = 0U;

    masterXfer.slaveAddress   = deviceAddress;
    masterXfer.direction      = kI3C_Write;
    masterXfer.busType        = kI3C_TypeI3CSdr;
    masterXfer.subaddress     = regAddress;
    masterXfer.subaddressSize = 1;
    masterXfer.data           = regData;
    masterXfer.dataSize       = dataSize;
    masterXfer.flags          = kI3C_TransferDefaultFlag;

    g_masterCompletionFlag = false;
    g_completionStatus     = kStatus_Success;
    result                 = I3C_MasterTransferNonBlocking(EXAMPLE_MASTER, &g_i3c_m_handle, &masterXfer);
    if (kStatus_Success != result)
    {
        return result;
    }

    while (!g_masterCompletionFlag)
    {
        timeout++;
        if ((g_completionStatus != kStatus_Success) || (timeout > I3C_TIME_OUT_INDEX))
        {
            break;
        }
    }

    if (timeout == I3C_TIME_OUT_INDEX)
    {
        result = kStatus_Timeout;
    }
    result = g_completionStatus;

    return result;
}
status_t I3C_ReadSensor(uint8_t deviceAddress, uint32_t regAddress, uint8_t *regData, size_t dataSize)
{
    status_t result                  = kStatus_Success;
    i3c_master_transfer_t masterXfer = {0};
    uint32_t timeout                 = 0U;

    masterXfer.slaveAddress   = deviceAddress;
    masterXfer.direction      = kI3C_Read;
    masterXfer.busType        = kI3C_TypeI3CSdr;
    masterXfer.subaddress     = regAddress;
    masterXfer.subaddressSize = 1;
    masterXfer.data           = regData;
    masterXfer.dataSize       = dataSize;
    masterXfer.flags          = kI3C_TransferDefaultFlag;

    g_masterCompletionFlag = false;
    g_completionStatus     = kStatus_Success;
    result                 = I3C_MasterTransferNonBlocking(EXAMPLE_MASTER, &g_i3c_m_handle, &masterXfer);
    if (kStatus_Success != result)
    {
        return result;
    }

    while (!g_masterCompletionFlag)
    {
        timeout++;
        if ((g_completionStatus != kStatus_Success) || (timeout > I3C_TIME_OUT_INDEX))
        {
            break;
        }
    }

    if (timeout == I3C_TIME_OUT_INDEX)
    {
        result = kStatus_Timeout;
    }
    result = g_completionStatus;

    return result;
}

void GPIO30_IRQHandler(void)
{
    /* Clear external interrupt flag. */
    GPIO_GpioClearInterruptFlags(GPIO3, 1U << 20);
	LightFlagt = GPIO_PinRead(GPIO3,20);
    /* Change state of button. */
    SDK_ISR_EXIT_BARRIER;
}
void GPIO00_IRQHandler(void)
{
    GPIO_GpioClearInterruptFlags(GPIO0, 1U << 6);
    /* Change state of button. */
    g_ButtonPress = true;
    SDK_ISR_EXIT_BARRIER;
}
static void i3c_master_callback(I3C_Type *base, i3c_master_handle_t *handle, status_t status, void *userData)
{
    if (status == kStatus_Success)
    {
        g_masterCompletionFlag = true;
    }
   // PRINTF("*********g_completionStatus****\r\n");

    g_completionStatus = status;
}
status_t p3t1755_set_dynamic_address(void)
{
    status_t result                  = kStatus_Success;
    i3c_master_transfer_t masterXfer = {0};
    uint8_t g_master_txBuff[1];

    /* Reset dynamic address. */
    g_master_txBuff[0]      = CCC_RSTDAA;
    masterXfer.slaveAddress = 0x7E;
    masterXfer.data         = g_master_txBuff;
    masterXfer.dataSize     = 1;
    masterXfer.direction    = kI3C_Write;
    masterXfer.busType      = kI3C_TypeI3CSdr;
    masterXfer.flags        = kI3C_TransferDefaultFlag;
    result                  = I3C_MasterTransferBlocking(EXAMPLE_MASTER, &masterXfer);
    if (result != kStatus_Success)
    {
        return result;
    }

    /* Assign dynmic address. */
    memset(&masterXfer, 0, sizeof(masterXfer));
    g_master_txBuff[0]      = CCC_SETDASA;
    masterXfer.slaveAddress = 0x7E;
    masterXfer.data         = g_master_txBuff;
    masterXfer.dataSize     = 1;
    masterXfer.direction    = kI3C_Write;
    masterXfer.busType      = kI3C_TypeI3CSdr;
    masterXfer.flags        = kI3C_TransferNoStopFlag;
    result                  = I3C_MasterTransferBlocking(EXAMPLE_MASTER, &masterXfer);
    if (result != kStatus_Success)
    {
        return result;
    }

    memset(&masterXfer, 0, sizeof(masterXfer));
    g_master_txBuff[0]      = SENSOR_ADDR << 1;
    masterXfer.slaveAddress = SENSOR_SLAVE_ADDR;
    masterXfer.data         = g_master_txBuff;
    masterXfer.dataSize     = 1;
    masterXfer.direction    = kI3C_Write;
    masterXfer.busType      = kI3C_TypeI3CSdr;
    masterXfer.flags        = kI3C_TransferDefaultFlag;
    return I3C_MasterTransferBlocking(EXAMPLE_MASTER, &masterXfer);
}

const i3c_master_transfer_callback_t masterCallback = {
    .slave2Master = NULL, .ibiCallback = NULL, .transferComplete = i3c_master_callback};

void float_to_str(char *str,double num)
{
     int high;//float_整数部分
     double low;//float_小数部分
     char *start=str;
     int n=0;
     char ch[20];
     int i;
     high=(int)num;
     low=num-high;

     while(high>0){
         ch[n++]='0'+high%10;
         high=high/10;
     }

     for(i=n-1;i>=0;i--){
         *str++=ch[i];
     }

     num -= (int)num;
     double tp = 0.1;
     *str++='.';

     while(num > 0.001){//精度限制
         num -= tp * (int)(low * 10);
         tp /= 10;
         *str++='0'+(int)(low*10);
         low=low*10.0-(int)(low*10);
     }
     *str='\0';
     str=start;
}


/*!
 * @brief Main function
 */
int main(void)
{
	status_t result                  = kStatus_Success;
    p3t1755_config_t p3t1755Config;
	i3c_master_config_t masterConfig;
	
    gpio_pin_config_t led_config = {
        kGPIO_DigitalOutput,
        1,
    };	

    gpio_pin_config_t sw_config = {
        kGPIO_DigitalInput,
        0,
    };
    /* Define the init structure for the output LED pin */
    gpio_pin_config_t motor_config = {
        kGPIO_DigitalOutput,
        0,
    };
    struct netif netif;
#if LWIP_IPV4
    ip4_addr_t netif_ipaddr, netif_netmask, netif_gw;
#endif /* LWIP_IPV4 */
    ethernetif_config_t enet_config = {.phyHandle   = &phyHandle,
                                       .phyAddr     = EXAMPLE_PHY_ADDRESS,
                                       .phyOps      = EXAMPLE_PHY_OPS,
                                       .phyResource = EXAMPLE_PHY_RESOURCE,
#ifdef configMAC_ADDR
                                       .macAddress = configMAC_ADDR
#endif
    };

    CLOCK_EnableClock(kCLOCK_InputMux);
    /* attach 12 MHz clock to FLEXCOMM0 (debug console) */
    CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
    CLOCK_EnableClock(kCLOCK_Gpio0);
	CLOCK_EnableClock(kCLOCK_Gpio1);
    CLOCK_EnableClock(kCLOCK_Gpio3);

    /* Attach PLL0 clock to I3C, 150MHz / 6 = 25MHz. */
    CLOCK_SetClkDiv(kCLOCK_DivI3c1FClk, 6U);
    CLOCK_AttachClk(kPLL0_to_I3C1FCLK);

    CLOCK_AttachClk(MUX_A(CM_ENETRMIICLKSEL, 0));
    CLOCK_EnableClock(kCLOCK_Enet);
    SYSCON0->PRESETCTRL2 = SYSCON_PRESETCTRL2_ENET_RST_MASK;
    SYSCON0->PRESETCTRL2 &= ~SYSCON_PRESETCTRL2_ENET_RST_MASK;


    BOARD_InitBootPins();
	BOARD_Init_i3c_Pins();

    BOARD_InitBootClocks();
    BOARD_InitDebugConsole();
    PRINTF("\r\n------------hello my eeworld.--------------\r\n");

    MDIO_Init();

    g_phy_resource.read  = MDIO_Read;
    g_phy_resource.write = MDIO_Write;

    time_init();

// config p3t temperature
    PRINTF("\r\nI3C master read sensor data example.\r\n");

    I3C_MasterGetDefaultConfig(&masterConfig);
    masterConfig.baudRate_Hz.i2cBaud          = EXAMPLE_I2C_BAUDRATE;
    masterConfig.baudRate_Hz.i3cPushPullBaud  = EXAMPLE_I3C_PP_BAUDRATE;
    masterConfig.baudRate_Hz.i3cOpenDrainBaud = EXAMPLE_I3C_OD_BAUDRATE;
    masterConfig.enableOpenDrainStop          = false;
    masterConfig.disableTimeout               = true;
    I3C_MasterInit(EXAMPLE_MASTER, &masterConfig, I3C_MASTER_CLOCK_FREQUENCY);

    /* Create I3C handle. */
    I3C_MasterTransferCreateHandle(EXAMPLE_MASTER, &g_i3c_m_handle, &masterCallback, NULL);

    result = p3t1755_set_dynamic_address();
    if (result != kStatus_Success)
    {
        PRINTF("\r\nP3T1755 set dynamic address failed.\r\n");
    }

    p3t1755Config.writeTransfer = I3C_WriteSensor;
    p3t1755Config.readTransfer  = I3C_ReadSensor;
    p3t1755Config.sensorAddress = SENSOR_ADDR;
    P3T1755_Init(&p3t1755Handle, &p3t1755Config);

// gpio inter
    GPIO_SetPinInterruptConfig(GPIO3, 20, kGPIO_InterruptEitherEdge);
    //EnableIRQ(GPIO31_IRQn);
	EnableIRQ(GPIO30_IRQn);
    GPIO_PinInit(GPIO3, 20, &sw_config);

    GPIO_SetPinInterruptConfig(GPIO0, 6, kGPIO_InterruptFallingEdge);

    EnableIRQ(GPIO00_IRQn);
    GPIO_PinInit(GPIO0, 6, &sw_config);


	//gpio 1 17 motor
    GPIO_PinInit(GPIO3, 19, &motor_config);

    // Set MAC address. 
#ifndef configMAC_ADDR
    (void)SILICONID_ConvertToMacAddr(&enet_config.macAddress);
#endif

    /* Get clock after hardware init. */
    enet_config.srcClockHz = EXAMPLE_CLOCK_FREQ;

#if LWIP_IPV4
    IP4_ADDR(&netif_ipaddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3);
    IP4_ADDR(&netif_netmask, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3);
    IP4_ADDR(&netif_gw, configGW_ADDR0, configGW_ADDR1, configGW_ADDR2, configGW_ADDR3);
#endif /* LWIP_IPV4 */

    lwip_init();

#if LWIP_IPV4
    netif_add(&netif, &netif_ipaddr, &netif_netmask, &netif_gw, &enet_config, EXAMPLE_NETIF_INIT_FN, ethernet_input);
#else
    netif_add(&netif, &enet_config, EXAMPLE_NETIF_INIT_FN, ethernet_input);
#endif /* LWIP_IPV4 */
    netif_set_default(&netif);
    netif_set_up(&netif);

#if LWIP_IPV6
    netif_create_ip6_linklocal_address(&netif, 1);
#endif /* LWIP_IPV6 */

    while (ethernetif_wait_linkup(&netif, 5000) != ERR_OK)
    {
        PRINTF("PHY Auto-negotiation failed. Please check the cable connection and link partner setting.\r\n");
    }
    PRINTF("\r\n*************************ready net somethin**********************************\r\n");

    //httpd_init();
	tcp_client_init();
#if LWIP_IPV6
    set_ipv6_valid_state_cb(netif_ipv6_callback);
#endif /* LWIP_IPV6 */

    PRINTF("\r\n***********************************************************\r\n");
    PRINTF(" tcp client example\r\n");
    PRINTF("***********************************************************\r\n");
#if LWIP_IPV4
    PRINTF(" IPv4 Address     : %u.%u.%u.%u\r\n", ((u8_t *)&netif_ipaddr)[0], ((u8_t *)&netif_ipaddr)[1],
           ((u8_t *)&netif_ipaddr)[2], ((u8_t *)&netif_ipaddr)[3]);
    PRINTF(" IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t *)&netif_netmask)[0], ((u8_t *)&netif_netmask)[1],
           ((u8_t *)&netif_netmask)[2], ((u8_t *)&netif_netmask)[3]);
    PRINTF(" IPv4 Gateway     : %u.%u.%u.%u\r\n", ((u8_t *)&netif_gw)[0], ((u8_t *)&netif_gw)[1],
           ((u8_t *)&netif_gw)[2], ((u8_t *)&netif_gw)[3]);
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
    print_ipv6_addresses(&netif);
#endif /* LWIP_IPV6 */
    PRINTF("***********************************************************\r\n");
    GPIO_PinInit(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PIN, &led_config);
    GPIO_PinInit(GPIO1, 2, &led_config);
    GPIO_PinInit(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PIN, &led_config);

    while (1)
    {
		//delay();
		//PRINTF("\r\n*********11111111111111111111**********\r\n");
        /* Poll the driver, get any outstanding frames */
        ethernetif_input(&netif);
        sys_check_timeouts(); /* Handle all system timeouts for all core protocols */
        
        result = P3T1755_ReadTemperature(&p3t1755Handle, &temperature);
        if (result != kStatus_Success){
            PRINTF("\r\nP3T1755 read temperature failed.\r\n");
        }
       // PRINTF("\r\nTemperature:%f -g_ButtonPress[%d]-LightFlagt[%d]\r\n", temperature,g_ButtonPress,LightFlagt);
		GPIO_PinWrite(GPIO3,19,LightFlagt);
		if(g_ButtonPress){
			char strss[100] = {0};
			char fstr[10] = {0};
			float_to_str(fstr,temperature);
			sprintf(strss,"btn:sw3;light:%lu;motor:%lu;temp:%s",LightFlagt,LightFlagt,fstr);
			g_ButtonPress = false;
			tcp_write(tpcb, strss, strlen(strss), 1);
            PRINTF(" %s is pressed temperature[%f]strss[%s]\r\n", btm,temperature,strss);
		}
        SDK_DelayAtLeastUs(100000, CLOCK_GetCoreSysClkFreq());
    }
}
#endif /* LWIP_TCP */
